package com.winit.cloudlink.message.internal.support;

import com.winit.cloudlink.message.exception.MessageSendException;
import com.winit.cloudlink.message.exception.RejectedMessageException;
import org.springframework.retry.*;
import org.springframework.retry.support.RetryTemplate;

public class RetryTemplateEx extends RetryTemplate {
	@Override
	protected boolean canRetry(RetryPolicy retryPolicy, RetryContext context) {
		Throwable lastException = context.getLastThrowable();
		if (lastException != null && lastException instanceof MessageSendException) {
			Throwable cause = lastException.getCause();
			if (cause != null && cause instanceof RejectedMessageException) {
				return false;
			}
		}
		return super.canRetry(retryPolicy, context);
	}
}
